module zysx {
	/**
	 *
	 * @author Don
	 *
	 */
	export class BaseComponent extends eui.Component {
		public _data: any;
		public eventDic: any;
		public constructor(data?: any) {
			super();
			this._data = data;
			this.eventDic = {};
			this.addEventListener(eui.UIEvent.CREATION_COMPLETE, this.onCreationComplete, this);
		}

		protected onCreationComplete(evt: eui.UIEvent): void {
			this.initComponent();
			egret.callLater(this.onOpen, this);
			this.removeEventListener(eui.UIEvent.CREATION_COMPLETE, this.onCreationComplete, this);
		}
		protected initComponent(): void {

		}
		protected onOpen(data?: any): void {
			if (data) this.data = data;
			egret.callLater(this.initListener, this);
		}
		/**
		 * @description 获取当前属于这个模块的数据
		 */
		public set data(data: any) {
			this._data = data;
		}

		public get data(): any {
			return this._data;
		}
		protected initListener(): void {
			zysx.NotifyMgr.registerNotify(zysx.StageMgr.STAGE_RESIZE, this.onStageResize, this);
		}
		protected onStageResize(): void {
			

		}
		public addEvent(target: egret.EventDispatcher, type: string, callBack: Function, thisObject: any): void {
			var eventParams: any = {};
			eventParams.target = target;
			eventParams.type = type;
			eventParams.callBack = callBack;
			eventParams.thisObject = thisObject;
			if (target) {
				target.addEventListener(type, callBack, thisObject);
				this.eventDic[target.hashCode + type] = eventParams;
			}
		}

		protected removeAllEvent(): void {
			let tempEvent;
			for (let name in this.eventDic) {
				tempEvent = this.eventDic[name];
				if (tempEvent.target != null) {
					tempEvent.target.removeEventListener(tempEvent.type, tempEvent.callBack, tempEvent.thisObject);
				}
				delete this.eventDic[name];
			}
			this.eventDic = {};
		}
		public onClose($isDispos: boolean = false): void {
			zysx.NotifyMgr.removeThisObjectNofity(this);
			this.removeAllEvent();
			this._data = null;
			if (this.parent) {
				this.parent.removeChild(this);
			}
		}

	}
	egret.registerClass(BaseComponent, "BaseComponent");
}
